#ifndef __C_DEVICE_MANAGER_H_INCLUDED__
#define __C_DEVICE_MANAGER_H_INCLUDED__

#include "IDeviceManager.h"
#include "IUserActionEventReceiver.h"

namespace game
{
	namespace scene
	{
		//! IGameSceneManager creator
		IGameSceneManager* createGameSceneManager(IDeviceManager* deviceManager);
	}

	namespace video
	{
		//! IVideoHandler creator
		IVideoHandler* createVideoHandler(IDeviceManager* deviceManager);
	}

	namespace io
	{
		IConfigReader* createConfigReader(IDeviceManager* deviceManager);
	}

	//! IUserActionEventReceiver creator
	IUserActionEventReceiver* createUserActionEventReceiver(IDeviceManager* deviceManager);

	//! This is the most important class of the game engine.You can access everything
	//! in the engine if you have a pointer to an instance of this class. 
	class CDeviceManager: public IDeviceManager
	{
	
	public:
		
		//!Default constructor
		CDeviceManager();

		//! Destructor
		virtual ~CDeviceManager();

		static CDeviceManager* Instance();

		void start();

		void stop();

		void clearScreen();

		virtual IUserActionEventReceiver* getUserEventReceiver();

		virtual irr::gui::IGUIEnvironment* getGUIEnvironment();

		virtual irr::scene::ISceneManager* getSceneManager();

		virtual scene::IGameSceneManager* getGameSceneManager();

		virtual io::IConfigReader* getConfigReader();

		virtual irrThread* getVideoThread();

		virtual irr::IrrlichtDevice* getVideoDevice();

		virtual bool getIsVideoDeviceRun();

		virtual video::IVideoHandler* getVideoHandler();

	private:

		video::IVideoHandler* VideoHandler;

		//! Needs for starts manager in individual thread
		void runVideo(void*data);

		irrThread* threadLock;

		u32 LastRenderTime;

		irrThread* VideoThread;

		irrThread* NetworkThread;

		irrThread* SoundThread;

		IUserActionEventReceiver* EventReceiver;
		u32 CurrentTime;

		//! Use for equal game speed on diff hardware
		f32 DeltaTime;

		//! If Irrlicht device run is True, otherwise - False
		bool IsVideoDeviceRun;
		bool IsLock;

		//! Represent a graphic device
		irr::IrrlichtDevice* VideoDevice;
		irr::video::IVideoDriver* VideoDriver;

		scene::IGameSceneManager* GameSceneManager;
		irr::scene::ISceneManager* SceneManager;
		irr::gui::IGUIEnvironment* GUI;

		io::IConfigReader* ConfigReader;

	};



}
#endif
